<template>
  <el-select size="mini" v-model="selCompany" placeholder="公司" @change="selEvent">
    <el-option v-for="company in companyList" :key="company.id" :label="company.companyName" v-model="company.id"></el-option>
  </el-select>
</template>

<script>
  import errHandler from '@/assets/errHandler'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  export default {
    name: "selCompany",
    props:['companyId'],
    data() {
      return {
        companyList:null,
        selCompany:null
      }
    },
    watch:{
      companyId(nv,ov){
        if(nv) this.init(nv)
      }
    },
    created(){
      this.init(this.companyId)
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      init(companyId){
        this.selCompany=companyId
        this.getCompanyList()
      },
      getCompanyList(){
        this.fetch({name:"getCompanyList"})
          .then(res=>{
            console.log('公司列表-----',res)
            this.companyList=res
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      selEvent(e){
        this.$emit('confirm',e)
      }
    }
  }
</script>

<style scoped>

</style>
